package com.ruoyi.products.controller;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.products.domain.BussCoupons;
import com.ruoyi.products.service.IBussCouponsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 套餐Controller
 *
 * @author star
 * @date 2025-06-06
 */
@RestController
@RequestMapping("/products/coupons")
public class BussCouponsController extends BaseController
{
    @Autowired
    private IBussCouponsService bussCouponsService;

    /**
     * 查询套餐列表
     */
//    @PreAuthorize("@ss.hasPermi('products:coupons:list')")
    @GetMapping("/list")
    public TableDataInfo list(BussCoupons bussCoupons)
    {
        startPage();
        List<BussCoupons> list = bussCouponsService.selectBussCouponsList(bussCoupons);
        return getDataTable(list);
    }

    /**
     * 导出套餐列表
     */
    @PreAuthorize("@ss.hasPermi('products:coupons:export')")
    @Log(title = "套餐", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BussCoupons bussCoupons)
    {
        List<BussCoupons> list = bussCouponsService.selectBussCouponsList(bussCoupons);
        ExcelUtil<BussCoupons> util = new ExcelUtil<BussCoupons>(BussCoupons.class);
        util.exportExcel(response, list, "套餐数据");
    }

    /**
     * 获取套餐详细信息
     */
    @PreAuthorize("@ss.hasPermi('products:coupons:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bussCouponsService.selectBussCouponsById(id));
    }

    /**
     * 新增套餐
     */
    @PreAuthorize("@ss.hasPermi('products:coupons:add')")
    @Log(title = "套餐", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BussCoupons bussCoupons)
    {
        bussCoupons.setCreatedAt(new Date());
        return toAjax(bussCouponsService.insertBussCoupons(bussCoupons));
    }

    /**
     * 修改套餐
     */
    @PreAuthorize("@ss.hasPermi('products:coupons:edit')")
    @Log(title = "套餐", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BussCoupons bussCoupons)
    {
        return toAjax(bussCouponsService.updateBussCoupons(bussCoupons));
    }

    /**
     * 删除套餐
     */
    @PreAuthorize("@ss.hasPermi('products:coupons:remove')")
    @Log(title = "套餐", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bussCouponsService.deleteBussCouponsByIds(ids));
    }
}
